<template>
  <div>
    <el-form>
      <el-row>
        <el-col :span="6">
          <el-form-item label="名称：">
            <el-input v-model="searchForm.name"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="1">
          <el-form-item label="地址：">
            <el-input v-model="searchForm.address"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="1">
          <el-form-item label="巡查人：">
            <el-input v-model="searchForm.true_name"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="上次巡检时间：">
            <el-date-picker
              v-model="patrolTime"
              type="daterange"
              placeholder="选择日期"
              format="YYYY 年 MM 月 DD 日"
              value-format="YYYY-MM-DD"
              >``
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :offset="2" :span="10">
          <el-button style="margin-left: 15px;" type="primary" @click="getLists">搜索</el-button>
          <el-button type="warning" @click="refreshBtn">重置</el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
  <div>
    <el-table :data="tableData" border style="width: 100%;">
      <el-table-column prop="id" label="ID" width="80"> </el-table-column>
      <el-table-column prop="point_name" label="名称"> </el-table-column>
      <el-table-column prop="address" label="点位详情"> </el-table-column>
      <el-table-column prop="time_unit" label="周期" :formatter="formatterTime_unit" width="80">
      </el-table-column>
      <el-table-column prop="address" label="位置"> </el-table-column>
      <el-table-column prop="last_time" label="上次巡查时间" :formatter="formatterDateTime">
      </el-table-column>
      <el-table-column prop="true_name" label="巡查人"> </el-table-column>
      <el-table-column prop="true_name" label="是否超期">
        <template #default="scope">
          <span :style="{ color: scope.row.patrol_status == 1 ? 'red' : 'green' }">
            {{ scope.row.patrol_status == 1 ? '是' : '否' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="is_pass" label="状态" width="100"></el-table-column>
      <el-table-column label="操作" width="100" fixed="right">
        <template #default="scope">
          <el-button size="mini" @click="showUnqualifiedDetailInfo(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @current-change="getLists"
        v-model:currentPage="tableDataInfo.page"
        :page-count="tableDataInfo.total_page"
        :total="tableDataInfo.total"
        background
        layout="total,prev, pager, next, jumper"
      >
      </el-pagination>
    </div>
    <el-dialog v-model="patrolPointDetailInfodialogVisible" width="60%">
      <el-scrollbar style="height: 50vh;">
        <patrolPointDetailInfo
          v-if="patrolPointDetailInfodialogVisible"
          :detailInfoObj="detailInfoObj"
        ></patrolPointDetailInfo>
      </el-scrollbar>
    </el-dialog>
  </div>
</template>

<script>
import patrolPointDetailInfo from '@/views/sociolUnitMange/patrolPointDetailInfo.vue'
export default {
  props: ['patrolPointType', 'patrolPointTypeId'],
  components: {
    patrolPointDetailInfo
  },
  data() {
    return {
      tableData: [],
      tableDataInfo: '',
      searchForm: {
        name: '', //点位名称
        address: '', //点位地址
        true_name: '' //巡查人
      },
      patrolTime: '',
      patrolPointDetailInfodialogVisible: false,
      detailInfoObj: ''
    }
  },

  created() {
    this.getLists()
  },
  computed: {
    unqualifiedDetailInfo() {
      if (this.patrolPointType == 'danger') return true
      else return false
    }
  },
  methods: {
    showUnqualifiedDetailInfo(row) {
      console.log(111)
      this.detailInfoObj = {
        // task_id:row.last_task_id,
        point_id: row.id
      }
      this.patrolPointDetailInfodialogVisible = true
    },
    refreshBtn() {
      this.patrolTime = ''
      let temp = this.searchForm
      for (let key in temp) {
        temp[key] = ''
      }
      this.searchForm = temp
      this.getLists()
    },
    formatterTime_unit(row, column, cellValue, index) {
      let temp = { 1: '天', 2: '周', 3: '月', 4: '季', 5: '年', 6: '2小时' }
      return temp[cellValue]
    },
    formatterDateTime(row, column, cellValue, index) {
      return this.$getDateTime(cellValue)
    },
    getLists(num) {
      let searchData = this.searchForm
      if (this.patrolTime.length) {
        searchData.start_time = this.patrolTime[0]
        searchData.end_time = this.patrolTime[1]
      }
      this.$api
        .post('/unit/UnitDuty/pointList', {
          page: num ? num : 1,
          rows: 8,
          list_status: this.patrolPointType,
          type_id: this.patrolPointTypeId,
          ...searchData
        })
        .then((res) => {
          this.tableData = res.data.list
          delete res.data.list
          this.tableDataInfo = res.data
        })
    }
  }
}
</script>

<style scoped>
.block {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 20px;
}
</style>
